package tq.com.tqteacher.message.model;

import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.RecursiveTask;

import tq.com.tqteacher.model.TQLogin;
import tq.com.tqteacher.model.TQUserInfo;

public class TQNoticeModel {
    private String content;
    private String from;
    private String date;
    private int seq_id;

    private TQUserInfo creator = new TQUserInfo();

    static public TQNoticeModel fromJson(JSONObject pObject){
        TQNoticeModel lTQNoticeModel = new TQNoticeModel();
        return lTQNoticeModel;
    }

    public TQNoticeModel(){
        creator.copy(TQLogin.getCurrent().getUserInfo());
    }

    public void refresh(JSONObject pObject){
        if(pObject == null);

        try {
            seq_id = pObject.optInt("id");
            content = pObject.optString("content");
            date = pObject.optString("create_time");

            JSONObject lObject = pObject.optJSONObject("creator");
            creator.refresh(lObject);
        }catch (Exception pe){

        }
    }

    public void onResult(JSONObject pObject){
        if(pObject == null)return;

        seq_id = pObject.optInt("seq_id");
    }
    public String getContent() {
        return content;
    }

    public void setContent(String pContent) {
        content = pContent;
    }

    public String getFrom() {
        return creator.getName();
    }

    public void setFrom(String pFrom) {
        from = pFrom;
    }

    public String getDate() {
        if(date == null){
            SimpleDateFormat lDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            return lDateFormat.format(new Date());
        }
        return date;
    }

    public int getSeq_id() {
        return seq_id;
    }

    public void setDate(String pDate) {
        date = pDate;
    }
}
